package kj.androidsync;

import roboguice.event.EventManager;

import com.google.inject.Inject;
import com.google.inject.Singleton;

@Singleton
public class Adder {
	
	@Inject
	EventManager eventManager;

	private boolean stop = false;
	private boolean started = false;
	private int counter = 0;

	public void startAddition() {
		if (!started) {
			this.eventManager.fire(new UpdateCounterEvent(this.counter));
			started = true;
			new Thread(new Runnable() {
				@Override
				public void run() {
					while (!stop) {
						try {
							Thread.sleep(2000);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
						counter++;
						eventManager.fire(new UpdateCounterEvent(counter));
					}
				}
			}).start();
		}
		else {
			this.eventManager.fire(new TestAlreadyStartedEvent());
		}
	}

}
